package proyecto.BusinessLogic;

import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import proyecto.DataAccessObject.VinculacionAlumnoDAORemote;
import proyecto.EntityBeans.VinculacionAlumno;

@Stateless
@Remote(VinculacionAlumnoBLRemote.class)
public class VinculacionAlumnoBL implements VinculacionAlumnoBLRemote {

	VinculacionAlumnoDAORemote vinculacionAlumnoDAORemote;
	
	public int save(VinculacionAlumno vinculacionAlumno) {	
		
		try
		{
			Context context = new InitialContext();
			vinculacionAlumnoDAORemote = (VinculacionAlumnoDAORemote) context.lookup("VinculacionAlumnoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return vinculacionAlumnoDAORemote.save(vinculacionAlumno); //alta de vinculacionAlumno		
		
	}
	
	
	public List findById(int idVinculacion, int idAlumno) {
		try
		{
			Context context = new InitialContext();
			vinculacionAlumnoDAORemote = (VinculacionAlumnoDAORemote) context.lookup("VinculacionAlumnoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return vinculacionAlumnoDAORemote.findByid(idVinculacion, idAlumno);
		
	}
	
	
	public VinculacionAlumno findByIdVA(int idVinculacionAlumno) {
		try
		{
			Context context = new InitialContext();
			vinculacionAlumnoDAORemote = (VinculacionAlumnoDAORemote) context.lookup("VinculacionAlumnoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return vinculacionAlumnoDAORemote.findByIdVA(idVinculacionAlumno);
		
	}
	
		
	public void merge(VinculacionAlumno vinculacionAlumno) {
		try
		{
			Context context = new InitialContext();
			vinculacionAlumnoDAORemote = (VinculacionAlumnoDAORemote) context.lookup("VinculacionAlumnoDAO/remote");
			vinculacionAlumnoDAORemote.merge(vinculacionAlumno);
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}	
		
	}
	
		
	public List findAll() {		
		try
		{
			Context context = new InitialContext();
			vinculacionAlumnoDAORemote = (VinculacionAlumnoDAORemote) context.lookup("VinculacionAlumnoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		return vinculacionAlumnoDAORemote.findAll();
	}
	
	
		
	public void remove(int idVinculacionAlumno){	
		try
		{
			Context context = new InitialContext();
			vinculacionAlumnoDAORemote = (VinculacionAlumnoDAORemote) context.lookup("VinculacionAlumnoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		vinculacionAlumnoDAORemote.remove(idVinculacionAlumno);
	}
	
}
